<?php
// +----------------------------------------------------------------------
// | Description: 菜单
// +----------------------------------------------------------------------
// | Author: linchuangbin <linchuangbin@honraytech.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\service\CategoryService;
use app\admin\validate\CategoryValidate;
use common\controller\AdminAuthController;
use think\response\Json;

/**
 * Class Category
 * @package app\admin\controller
 * @property CategoryService $service
 * @property CategoryValidate $validate
 */
class Category extends AdminAuthController
{

    /**
     * @return bool|void
     */
    public function initialize()
    {
        parent::initialize();
        $this->service = CategoryService::instance();
        $this->validate = CategoryValidate::instance();
        return true;
    }

    /**
     * @return Json
     */
    public function index(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $list = $this->service->getList($param);
        $count = $this->service->getCount($param);
        return $this->json_responce(compact(['list', 'count']));
    }

    /**
     * @return Json
     */
    public function read(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->getByID($param);
        return $this->json_responce($data);
    }

    /**
     * @return Json
     */
    public function save(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->createData($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function update(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->updateByID($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function delete(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->delByID($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function deletes(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->delByIDs($param);
        return $this->json_responce();
    }

    /**
     * @return Json
     */
    public function enables(): Json
    {
        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->service->enableByIDs($param);
        return $this->json_responce();
    }
}